package com.io;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

/**
 * 在控制台上输入一段字符，
 * 通过BufferedOutputStream将字符写到缓冲输出流中，要求写10次。
 *
 * @author: Jovi
 * @createTime: 2017-06-09 14:49
 **/
public class BufferTest {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;
        try {
            fos = new FileOutputStream("b.txt");
            bos = new BufferedOutputStream(fos);
            System.out.println("Enter the content that you want to store");
            String msg = sc.next();
            byte [] ob = msg.getBytes();
            for (int i = 0; i < 10; i++) {
                bos.write(ob,0,ob.length);
            }
            bos.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                bos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
